/*
 * @Description: 
 * @Author: 邢
 * @Date: 2021-04-20 22:44:48
 * @LastEditTime: 2021-04-21 00:11:59
 * @LastEditors: 邢
 */
//路由拦截和仓库配置
import { RequestConfig } from 'umi';
import {message} from "antd"
import React from 'react';
//在跟组件注入store仓库
import store from "@/store"
import StoreContext from './context/StoreContext';

export const request: RequestConfig = {
  timeout: 1000,
  errorConfig: {},
  middlewares: [],
  requestInterceptors: [(url, options) => {
    return {
      url: `${url}&interceptors=yes`,
      options: { ...options, interceptors: true },
    };
  }],
  responseInterceptors: [response => {
        const codeMaps:{[key:string]:any} = {
            500:'服务器有误',
            404:'资源不存在',
            401:'鉴权失败',
            403:'携带信息有误',
            502: '网关错误。',
            503: '服务不可用，服务器暂时过载或维护。',
            504: '网关超时。',
        };
        message.error(codeMaps[response.status]);
        return response;
      }
  ],
};


export function rootContainer(container:any) {
    return React.createElement(StoreContext.Provider, {value:store}, container);
}